"""
@Author  : 康帅
@Time    : 2021/3/10 15:18
@Function: 监听模式的框架模型
"""
from abc import ABCMeta, abstractmethod


class Observer(metaclass=ABCMeta):
    """观察者基类"""

    @abstractmethod
    def update(self, observable, objects):
        pass


class Observable:
    """被观察者基类"""

    def __init__(self):
        self.__observers = []

    def add_ob_server(self, observer):
        """ 添加 """
        self.__observers.append(observer)

    def remove_ob_server(self, observer):
        """ 移除 """
        self.__observers.remove(observer)

    def notify_ob_servers(self, objects=0):
        """ 观察者(会调用Observer基类) """
        for o in self.__observers:
            o.update(self, objects)
